package com.avcdata.aoscustommade.presenter;

import com.avcdata.aoscustommade.bean.BaseResponseBean;
import com.avcdata.aoscustommade.bean.TopBrandAndSelfBrandBean;
import com.avcdata.aoscustommade.main.BaseCallBack;
import com.avcdata.aoscustommade.model.MainActivityModel;
import com.avcdata.aoscustommade.view.MainActivityView;

import org.json.JSONObject;

/**
 * 主页的presenter
 * Created by zyh on 17/6/7.
 */

public class MainActivityPresenter {
    private final MainActivityView mainActiivityView;
    private final MainActivityModel mainActivityModel;

    public MainActivityPresenter(MainActivityView mainActiivityView, MainActivityModel mainActivityModel) {
        this.mainActiivityView = mainActiivityView;
        this.mainActivityModel = mainActivityModel;
    }

    /**
     * 获取品牌排行
     *
     * @param category
     * @param lastWeek
     */
    public void loadBrandList(String category, int topBrandCount, int lastWeekCount, String lastWeek, String bigRegion, String officeName, String cityName, String brand, String secretKey) {
        mainActivityModel.loadBrandList(category, topBrandCount, lastWeekCount, lastWeek, bigRegion, officeName, cityName, brand, secretKey, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                mainActiivityView.loadBrandListSuccess((TopBrandAndSelfBrandBean) object);
            }

            @Override
            public void onFailure() {
                mainActiivityView.loadBrandFailure();
            }


            @Override
            public void onFailure(Throwable throwable) {
                mainActiivityView.loadBrandFailure(throwable);
            }
        });
    }

    /**
     * 全国走势图
     *
     * @param module_typeString
     * @param lastWeek
     */
    public void loadNationalTrend(String module_typeString, String brand, int topBrandCount, int lastWeekCount, String lastWeek, String bigRegion, String officeName, String cityName) {
        mainActivityModel.loadNationalTrend(module_typeString, brand, topBrandCount, lastWeekCount, lastWeek, bigRegion, officeName, cityName, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                mainActiivityView.loadNationThrendSuccess((JSONObject) object);
            }

            @Override
            public void onFailure() {
                mainActiivityView.loadNationThrendFailure();
            }


            @Override
            public void onFailure(Throwable throwable) {
                mainActiivityView.loadNationThrendFailure(throwable);
            }
        });
    }

    /**
     * 行业销售额同环比
     *
     * @param lastWeek
     */
    public void loadIndustrySales(String lastWeek) {
        mainActivityModel.loadIndustrySales(lastWeek, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                mainActiivityView.loadIndustrySalesSuccess((JSONObject) object);
            }

            @Override
            public void onFailure() {
                mainActiivityView.loadIndustrySalesFailure();
            }


            @Override
            public void onFailure(Throwable throwable) {
                mainActiivityView.loadIndustrySalesFailure(throwable);
            }
        });
    }

    /**
     * 行业市占饼图
     *
     * @param lastWeek
     */
    public void loadPiePicture(String lastWeek) {
        mainActivityModel.loadPiePicture(lastWeek, new BaseCallBack() {
            @Override
            public void onSuccess(Object object) {
                mainActiivityView.loadPiePictureSuccess((JSONObject) object);
            }

            @Override
            public void onFailure() {
                mainActiivityView.loadPiePictureFailure();
            }


            @Override
            public void onFailure(Throwable throwable) {
                mainActiivityView.loadPiePictureFailure(throwable);
            }
        });
    }
}
